import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Thread21 {
    public static void main(String[] args)throws InterruptedException {
        Callable<Integer>b=new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int count=0;
                for(int i=1;i<=1000;i++)
                {
                    count+=i;
                }
                return count;
            }
        };
        FutureTask<Integer>futureTask=new FutureTask<>(b);
        Thread t1=new Thread(futureTask);
        t1.start();
        t1.join();
        try {
            int result=futureTask.get();
            System.out.println(result);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }

    }
}
